extends StateBase

##状态所属
@export var enemy: BaseEnemy

func enter() -> void:
	super.enter()
	enemy.animation_player.play("hurt")
	
	if enemy.stats.energy_shield >= enemy.pending_damage.amount:
		enemy.stats.energy_shield -= enemy.pending_damage.amount
	else:
		enemy.pending_damage.amount -= enemy.stats.energy_shield
		enemy.stats.energy_shield = 0
		enemy.stats.structural_strength -= enemy.pending_damage.amount
	
	if enemy.stats.structural_strength == 0:
		state_machine.change_state("Dying")
	
	enemy.pending_damage = null

func physics_process_update(delta: float) -> void:
	super.physics_process_update(delta)
	if not enemy.animation_player.is_playing():
		state_machine.change_state("Running")
	
	enemy.move(enemy.VELOCITY, enemy.speed / 2)
